package com.vlada.studzad.pages;

import org.apache.tapestry5.annotations.ApplicationState;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;

import com.vlada.studzad.data.MockDataJobOfferSource;
import com.vlada.studzad.data.MockDataStudentSource;
import com.vlada.studzad.model.JobOffer;
import com.vlada.studzad.model.Privilege;
import com.vlada.studzad.model.Student;
import com.vlada.studzad.model.User;

public class CreateJobOffer {
	
	@ApplicationState
	@Property
	private User user;
	private boolean userExists;	
	
	Object onActivate() {
		if (!userExists)return Index.class;
		else if(user.getPrivilege()==Privilege.EMPLOYER){
			return null;
		}
		return Index.class;
	}
	
	@ApplicationState
	private MockDataJobOfferSource jobOffers;
	
	@Persist
	private JobOffer jobOffer;

	public JobOffer getJobOffer() {
		return jobOffer;
	}

	public void setJobOffer(JobOffer jobOffer) {
		this.jobOffer = jobOffer;
	}


	Object onSuccess()
    {
        jobOffers.addJobOffer(jobOffer);
        jobOffer = null;

        return null;
    }
	
}
